<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- This file documents the use of the GNU compilers.

Copyright © 1988-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below).  A copy of the license is included in the section entitled
"GNU Free Documentation License".

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<title>Invoking G++ (Using the GNU Compiler Collection (GCC))</title>

<meta name="description" content="Invoking G++ (Using the GNU Compiler Collection (GCC))">
<meta name="keywords" content="Invoking G++ (Using the GNU Compiler Collection (GCC))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="index.html" rel="start" title="Top">
<link href="Indices.html" rel="index" title="Indices">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Invoking-GCC.html" rel="up" title="Invoking GCC">
<link href="C-Dialect-Options.html" rel="next" title="C Dialect Options">
<link href="Overall-Options.html" rel="prev" title="Overall Options">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
kbd.key {font-style: normal}
span:hover a.copiable-link {visibility: visible}
-->
</style>


</head>

<body lang="en_US">
<div class="section-level-extent" id="Invoking-G_002b_002b">
<div class="nav-panel">
<p>
Next: <a href="C-Dialect-Options.html" accesskey="n" rel="next">Options Controlling C Dialect</a>, Previous: <a href="Overall-Options.html" accesskey="p" rel="prev">Options Controlling the Kind of Output</a>, Up: <a href="Invoking-GCC.html" accesskey="u" rel="up">GCC Command Options</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Indices.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h3 class="section" id="Compiling-C_002b_002b-Programs"><span>3.3 Compiling C++ Programs<a class="copiable-link" href="#Compiling-C_002b_002b-Programs"> &para;</a></span></h3>

<a class="index-entry-id" id="index-suffixes-for-C_002b_002b-source"></a>
<a class="index-entry-id" id="index-C_002b_002b-source-file-suffixes"></a>
<p>C++ source files conventionally use one of the suffixes &lsquo;<samp class="samp">.C</samp>&rsquo;,
&lsquo;<samp class="samp">.cc</samp>&rsquo;, &lsquo;<samp class="samp">.cpp</samp>&rsquo;, &lsquo;<samp class="samp">.CPP</samp>&rsquo;, &lsquo;<samp class="samp">.c++</samp>&rsquo;, &lsquo;<samp class="samp">.cp</samp>&rsquo;, or
&lsquo;<samp class="samp">.cxx</samp>&rsquo;; C++ header files often use &lsquo;<samp class="samp">.hh</samp>&rsquo;, &lsquo;<samp class="samp">.hpp</samp>&rsquo;,
&lsquo;<samp class="samp">.H</samp>&rsquo;, or (for shared template code) &lsquo;<samp class="samp">.tcc</samp>&rsquo;; and
preprocessed C++ files use the suffix &lsquo;<samp class="samp">.ii</samp>&rsquo;.  GCC recognizes
files with these names and compiles them as C++ programs even if you
call the compiler the same way as for compiling C programs (usually
with the name <code class="command">gcc</code>).
</p>
<a class="index-entry-id" id="index-g_002b_002b"></a>
<a class="index-entry-id" id="index-c_002b_002b"></a>
<p>However, the use of <code class="command">gcc</code> does not add the C++ library.
<code class="command">g++</code> is a program that calls GCC and automatically specifies linking
against the C++ library.  It treats &lsquo;<samp class="samp">.c</samp>&rsquo;,
&lsquo;<samp class="samp">.h</samp>&rsquo; and &lsquo;<samp class="samp">.i</samp>&rsquo; files as C++ source files instead of C source
files unless <samp class="option">-x</samp> is used.  This program is also useful when
precompiling a C header file with a &lsquo;<samp class="samp">.h</samp>&rsquo; extension for use in C++
compilations.  On many systems, <code class="command">g++</code> is also installed with
the name <code class="command">c++</code>.
</p>
<a class="index-entry-id" id="index-invoking-g_002b_002b"></a>
<p>When you compile C++ programs, you may specify many of the same
command-line options that you use for compiling programs in any
language; or command-line options meaningful for C and related
languages; or options that are meaningful only for C++ programs.
See <a class="xref" href="C-Dialect-Options.html">Options Controlling C Dialect</a>, for
explanations of options for languages related to C.
See <a class="xref" href="C_002b_002b-Dialect-Options.html">Options Controlling C++ Dialect</a>, for
explanations of options that are meaningful only for C++ programs.
</p>
</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="C-Dialect-Options.html">Options Controlling C Dialect</a>, Previous: <a href="Overall-Options.html">Options Controlling the Kind of Output</a>, Up: <a href="Invoking-GCC.html">GCC Command Options</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Indices.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
